/*
 * ============================================================================
 *
 *       Filename:  sha256.c
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2020年09月07日 02时45分15秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  jianxi sun (jianxi), ycsunjane@gmail.com
 *   Organization:  
 *
 * ============================================================================
 */
#include <stdio.h>
#include <stdint.h>

#include <openssl/hmac.h>
#include <string.h>
#include <stdio.h>

int main(int argc,char* argv[])
{
	if(argc != 3){
	  printf("key data is required\n");
	  exit(1);
	}
	//unsigned char *key = (unsigned char*)"webapi4RYhVJY1BTJ1Fo62jEvlcABA11";
	//unsigned char *data = (unsigned char*) "5f2b7a2ac7e67227c313b4f1C605040759AA1599445127000";
	unsigned char *key = (unsigned char*) argv[1];
	unsigned char *data = (unsigned char*) argv[2];
	
	unsigned char *result;
	int result_len = 32;
	int i;
	static char res_hexstring[32];
	
	result = HMAC(EVP_sha256(), key, strlen((char *)key), data, strlen((char *)data), NULL, NULL);
	for (i = 0; i < result_len; i++) {
	  sprintf(&(res_hexstring[i * 2]), "%02x", result[i]);
	}
	printf("%s\n", res_hexstring);
	return 0;
}
